//
//  SinaComposeToolBar.swift
//  SinaWeibo
//
//  Created by 王朝阳 on 2016/11/6.
//  Copyright © 2016年 wangzhaoyang. All rights reserved.
//

import UIKit

@available(iOS 9.0, *)
class SinaComposeToolBar: UIStackView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI() {
        backgroundColor = UIColor.red
        //设置水平方向布局
        axis = .horizontal
        //设置子控件的填充模式
        distribution = .fillEqually
        
        addChildButton(imageName: "compose_camerabutton_background")
        addChildButton(imageName: "compose_mentionbutton_background")
        addChildButton(imageName: "compose_trendbutton_background")
        addChildButton(imageName: "compose_emoticonbutton_background")
        addChildButton(imageName: "compose_add_background")

    }
    //MARK: - 添加子控件
    private func addChildButton(imageName: String) {
        
        let button = UIButton()
        button.setImage(UIImage(named: imageName), for: .normal)
        button.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
        button.setBackgroundImage(UIImage(named: "compose_toolbar_background"), for: .normal)
        //取消高亮效果
        button.adjustsImageWhenHighlighted = false
        //添加控件
        addArrangedSubview(button)
        
    }
}
